package com.hhxy.string;

import java.util.Scanner;

public class JudgeLogin {
    public static void main(String[] args) {
        if (judgeLogin()) {
            System.out.println("恭喜您，登录成功！");
        }else{
            System.out.println("对不起，登录失败！");
        }
    }
    private static boolean judgeLogin() {
        Scanner sc = new Scanner(System.in);
        String correctUserName = "ghp";
        String correctPassword = "666";
        boolean f = true;
        for (int i = 0; i < 3; i++) {
            System.out.println("请您输入用户名：");
            String userName = sc.next();
            System.out.println("请您输入用户密码：");
            String password = sc.next();
            f = true;
            if (correctUserName.equals(userName)) {
                if (correctPassword.equals((password))) {
                    break;
                } else {
                    f = false;
                    System.out.println("用密码输入错误，您还有" + (2 - i) + "次机会输入！");
                }
            } else {
                f = false;
                System.out.println("用户名输入错误，您还有" + (2 - i) + "次机会输入！");
            }
        }
        return f;
    }
}
